package cn.jbt.api.admin.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.jbt.api.admin.entity.vo.UserInfoVO;
import cn.jbt.api.admin.service.SysLoginService;
import cn.jbt.common.UsernameAndPassword;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/login")
@Slf4j
@AllArgsConstructor
public class SysLoginController {

    private final SysLoginService sysLoginService;

    /**
     * <h2>系统登陆</h2>
     */
    @PostMapping("/token")
    public SaTokenInfo token(@Valid @RequestBody UsernameAndPassword usernameAndPassword) {
        return sysLoginService.token(usernameAndPassword);
    }

    /**
     * <h2>获取登陆用户信息</h2>
     */
    @PostMapping("/userInfo")
    public UserInfoVO getUserInfo() {
        return sysLoginService.getUserInfo();
    }

}
